<!DOCTYPE html>
<html lang="en">
<head>
<body>
<h2>Break Statement</h2>
<script>
for (let i = 0; i < 10; i++) {
if (i === 5) {
break; // Exit the loop when i is 5
}
console.log(i);
}// Output: 0, 1, 2, 3, 4
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<h2>Continue Statement</h2>
<script>
for (let i = 0; i < 10; i++) {
if (i === 5) {
continue; // Skip the iteration when i is 5
}
console.log(i);
}
</script>
</body>
</html>
// Output: 0, 1, 2, 3, 4, 6, 7, 8, 9
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<h2>Break in Nested Loops</h2>
<script>
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (i === 1 && j === 1) {
break; // Exit the inner loop when i is 1 and j is 1
}
console.log(i, j);
}
}
</script>
</body>
</html>
// Output: 0 0, 0 1, 0 2, 1 0
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<h2>Break in Nested Loops</h2>
<script>
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (j === 1) {
continue; // Skip the iteration when j is 1
}
console.log(i, j);
}
}
</script>
</body>
</html>
// Output: 0 0, 0 2, 1 0, 1 2, 2 0, 2 2